﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using ProjectHK3.App_Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectHK3.Object_One
{
    public partial class CreateDistance : System.Web.UI.Page
    {
        B_LoadDrop ex = new B_LoadDrop();
        DataTable tb = new DataTable();
        B_Insert bi = new B_Insert();
        Distances dis = new Distances();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = ex.Bran();
                DropDownList1.DataTextField = "BRANCH_NAME";
                DropDownList1.DataValueField = "BRANCH_ID";
                DropDownList1.DataBind();

                DropDownList2.DataSource = ex.Bran();
                DropDownList2.DataTextField = "BRANCH_NAME";
                DropDownList2.DataValueField = "BRANCH_ID";
                DropDownList2.DataBind();
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            dis.KM = int.Parse(TextBox1.Text.ToString());
            dis.BRANCH_ID_FROM = int.Parse(DropDownList1.SelectedValue.ToString());
            dis.BRANCH_ID_TO = int.Parse(DropDownList2.SelectedValue.ToString());
            if (bi.InsertDistance(dis) == true)
            {
                Alert.Show("Insert Sucessful!!!");
            }
            else
            {
                Alert.Show("Insert Fail. Please try again!!!");
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            TextBox1.Text = "";
            DropDownList1.SelectedIndex = 0;
            DropDownList2.SelectedIndex = 0;
            TextBox1.Focus();
        }
    }
}